package com.tulele.vtool.service.impl;

import com.tulele.vtool.mapper.BrandInfoMapper;
import com.tulele.vtool.model.BrandCategory;
import com.tulele.vtool.model.BrandInfo;
import com.tulele.vtool.model.combinedEntity.SearchBrandInfo;
import com.tulele.vtool.service.IBrandInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandInfoServiceImpl implements IBrandInfoService {

    @Autowired
    private BrandInfoMapper brandInfoMapper;

    @Override
    public List<BrandInfo> getBrandInfo() {
        return brandInfoMapper.queryBrandInfo();
    }

    @Override
    public String getBrandInfoByBrandId(Integer brandId) {
        return brandInfoMapper.queryBrandInfoByBrandId(brandId);
    }

    @Override
    public String getBrandInfoTempByBrandId(Integer brandId) {
        return brandInfoMapper.queryBrandInfoTempByBrandId(brandId);
    }

    @Override
    public List<SearchBrandInfo> getBrandInfoByBrandName(String brandName) {
        return brandInfoMapper.queryBrandInfoByBrandName(brandName);
    }

    @Override
    public List<BrandInfo> getRecommendBrandInfo() {
        return brandInfoMapper.queryRecommendBrandInfo();
    }

    @Override
    public int recordBrandInfo(BrandInfo brandInfo) {

        BrandInfo queryBrandInfo = new BrandInfo();
        queryBrandInfo.setUserId(brandInfo.getUserId());
        queryBrandInfo.setBrandName(brandInfo.getBrandName());

        BrandInfo userBrandInfoInDB = brandInfoMapper.queryUserBrandInfoByBrandName(queryBrandInfo);
        if (userBrandInfoInDB == null) {

            brandInfoMapper.addBrandInfo(brandInfo);
            return brandInfo.getId();

        }

        return 0;
    }

    @Override
    public int modifyBrandInfo(BrandInfo brandInfo) {
        return brandInfoMapper.updBrandInfo(brandInfo);
    }

    @Override
    public List<BrandCategory> getAllCategory() {
        BrandCategory brandCategory= new BrandCategory();
        brandCategory.setCategoryFlag(1);//展示状态（0停用 1正常）
        return brandInfoMapper.queryAllCategory(brandCategory);
    }

    @Override
    public List<BrandInfo> getRecommendBrandForBigCategory(Integer bigCategory) {
        return brandInfoMapper.getRecommendBrandForBigCategory(bigCategory);
    }
}
